<?php
class Zendvn_Validate_Form{
	protected  $_arrError;
	
	protected $_arrData;
	public function changeObject($value,$options = null){
		switch ($value) {
			case 'Alnum':
				return new Zend_Validate_Alnum($options);
				break;
			case 'Alpha':
				return new Zend_Validate_Alpha($options);
				break;
			case 'Between':
				return new Zend_Validate_Between($options);
				break;
			case 'Date':
				return new Zend_Validate_Date($options);
				break;
			case 'RecordExists':
				return new Zend_Validate_Db_RecordExists($options);
				break;				
			case 'NoRecordExists':
				return new Zend_Validate_Db_NoRecordExists($options);
				break;
			case 'Digits':
				return new Zend_Validate_Digits();
				break;				
			case 'EmailAddress':
				return new Zend_Validate_EmailAddress();
				break;
			case 'Float':
				return new Zend_Validate_Float();
				break;
			case 'GreaterThan':
				return new Zend_Validate_GreaterThan($options);
				break;
			case 'InArray':
				return new Zend_Validate_InArray($options);
				break;
			case 'Int':
				return new Zend_Validate_Int();
				break;
			case 'Ip':
				return new Zend_Validate_Ip();
				break;
			case 'LessThan':
				return new Zend_Validate_LessThan($options);
				break;
			case 'NotEmpty':
				return new Zend_Validate_NotEmpty();
				break;
			case 'StringLength':
				return new Zend_Validate_StringLength($options);
				break;
			
			case 'Regex':
				return new Zend_Validate_Regex($options);
				break;
				
			case 'ZendvnPhone':
				return new Zendvn_Validate_Phone();
				break;
			case 'PassConfirm':
				return new Zendvn_Validate_PassConfirm($options);
				break;
			case 'ZendvnRegex':
				return new Zendvn_Validate_Regex($options);
				break;
			case 'ZendvnUrl':
					return new Zendvn_Validate_Url($options);
					break;
			default:
				return false;
				break;
		}
		
	}
	public function validate($data,$arrParam){

		$validator 	= new Zend_Validate();
	    $options 	= null;
		if(count($data)){
			foreach($data as $key=>$val){
				if(!is_array($val['type'])){
					$options = $val['type'];
				}
				if(count($val['type'])>1){
					$options = $val['type'];
				}
				if($this->changeObject($val['name'],$options)) 
					$validator->addValidator($this->changeObject($val['name'],$options),true); 
			}

		}
		return $validator;
	}
}